package com.wl.tp.protocol;

public class NetInteger implements INetType {

	private int intValue;

	public NetInteger() {
	}

	public NetInteger(int intvalue) {
		this.intValue = intvalue;
	}

	public int parse(byte[] bytes, int index) {
		this.intValue = DataBuilder.getIntFromNetworkOrder(bytes, index);
		return 4;
	}

	public byte[] toBytes() {
		byte[] bytes = new byte[4];
		DataBuilder.setIntToNetworkOrder(bytes, 0, this.getIntValue());
		return bytes;
	}

	public String toString() {
		return Integer.valueOf(this.getIntValue()).toString();
	}

	public int getIntValue() {
		return intValue;
	}

	public void setIntValue(int intValue) {
		this.intValue = intValue;
	}



	public static int getIntValueFromByte(byte[] value) {
		NetInteger netInt = new NetInteger();
		netInt.parse(value, 0);
		return netInt.getIntValue();
	}

}
